﻿using System;
using System.Data.SqlClient;
using com.fukefu.sql;
using dotnetCHARTING.WinForms;

namespace com.fukefu
{
    public class MyChart
    {
        SqlServerOperate sql = new SqlServerOperate();
        Chart chart;
        public MyChart(ref Chart chart)
        {
            this.chart = chart;
            //生成图片
            chart.LegendBox.Template = "none";
            chart.DefaultSeries.Type = SeriesType.Spline;
            chart.ShadingEffect = false;
            chart.ShowDateInTitle = true;
            chart.DefaultSeries.DefaultElement.ShowValue = true;//拐点显示数字
            chart.XAxis.TickLabelMode = TickLabelMode.Normal;
        }
        public void FlushData(string cmd)
        {
            chart.SeriesCollection.Clear();
            chart.SeriesCollection.Add(GetSC(cmd));
            chart.Refresh();
        }
        private SeriesCollection GetSC(string cmd)
        {
            SeriesCollection sc = new SeriesCollection();
            SqlDataReader re = sql.Query(cmd);
            Series s = new Series();
            while (re.Read())
            {
                Element e = new Element();
                e.Name = re[0].ToString();
                e.YValue = Convert.ToDouble(re[1]);
                s.Elements.Add(e);
            }
            re.Close();
            sc.Add(s);
            return sc;
        }
    }
}
